function debounce (fn, wait) {
  let timer;
  
  return function() {

    if (timer) clearTimeout(timer);

    // 不用的话this会指向window
    const context = this;
    const args = arguments;

    timer = setTimeout(function () {
      fn.apply(context, args);
    }, wait);
  }
}

function test() {
  console.log('ceshi1')
}


const debounceTest = debounce(test, 1000);
debounceTest()
debounceTest()
debounceTest()